﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class DeliverGoodsManagement_Settlement : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("700100");
        if (!IsPostBack)
        {
            AspNetPager1.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["RowCountPerPage"].ToString());
            Bind();
        }

        Session["FCode"] = "700100";
    }

    private void Bind()
    {
        try
        {
            string sqlstr = "";
            sqlstr += txtPayDocId.Text.Trim() == "" ? "" : " and PD_ID LIKE '%" + txtPayDocId.Text.Trim() + "%' ";
            sqlstr += txtCustomerId.Text.Trim() == "" ? "" : " and PD_CUSTOMERCODE like '%" + txtCustomerId.Text.Trim() + "%' ";
            sqlstr += txtPayDocStartDate.Text.Trim() == "" ? "" : " and PD_CREATEDATE>='" + txtPayDocStartDate.Text.Trim() + "' ";
            sqlstr += txtPayDocEndDate.Text.Trim() == "" ? "" : " and PD_CREATEDATE<='" + txtPayDocEndDate.Text.Trim() + "' ";
            sqlstr += dropCheck.SelectedValue.Trim() == "-1" ? "" : " and PD_CHECK='" + dropCheck.SelectedValue + "' ";
            sqlstr += dropClearType.SelectedValue.Trim() == "-1" ? "" : " and PD_CLEARTYPE='" + dropClearType.SelectedValue + "' ";


            int recordCount;
            DataSet dst = new BLL.PAYDOC().GetPayDoc(GetStartIndex(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize), AspNetPager1.PageSize, sqlstr, out recordCount);
            PAYDOCListControl1.Bind(dst);
            AspNetPager1.RecordCount = recordCount;
        }
        catch (Exception ex)
        {
            Share.Alert(this.Page, ex.Message);
        }
        
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }


    protected void btnAddSettlement_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddSettlement.aspx");
    }

    private int GetStartIndex(int pageIndex, int pageSize)
    {
        return 1 + (pageIndex - 1) * pageSize;
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Bind();
    }
}
